package com.uenpay.im.panel.emoji;

import android.text.Selection;
import android.text.Spannable;
import android.text.TextUtils;
import android.widget.EditText;

import com.qyx.android.weight.edittext.Emoji;
import com.uenpay.im.IMApplication;
import com.uenpay.im.R;

/**
 * emoji
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class QyxEmoji extends Emoji{

	public final String[] _texts = new String[] {
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_ho_ho),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_smirk),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_lol),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_love),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_confused),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_tearing),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_food_lover),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_crazy),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_hum),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_loverly),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_angry),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sweating),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_shy),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sleep),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_cash),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_snickering),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_cool),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_unlucky),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_surprised),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_shut_up),
			"",
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_dispise),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_dig_nose),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_play_boy),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_clap),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sorrow),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_thinking),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sick),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_kissing),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_scold),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_very_happy),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_hush),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_disgusting),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_speechless),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_pitiful),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sleepy),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_yawn),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_disappoint),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_unfair),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sly),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_make_a_face),
			"",
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_nerdy),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_have_a_cold),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_doubt),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_byebye),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_agree),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_furous),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_e_t),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_magic_horse),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_awesome),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_dumb),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_acting_cute),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_panda),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_hare),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_embarrassed),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_handsome),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_powerful_of_diginifying),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_spectator),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_no),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_good),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_ha_ha),
			"",
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_come),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_ok),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_fist),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_thumbsdown),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_handshake),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_yeah),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_thumbsup),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_pinky),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_loving),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_like),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_brokenheart),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_cake),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_flower),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_cheers),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_coffee),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_gift),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_watermelon),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_popsicle),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_football),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_camera),
			"",
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_clock),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_music),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_microphone),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_automobile),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_fan),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_movie),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_airplane),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_mobile_phone),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_internship),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_the_sun),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_floating_clouds),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_rain),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_sand_storm),
			IMApplication.getAppContext().getResources()
					.getString(R.string.emoji_the_moon), "" };
	public final int[] _resourceId = { R.raw.mood00, R.raw.mood01,
			R.raw.mood02, R.raw.mood03, R.raw.mood04, R.raw.mood05,
			R.raw.mood06, R.raw.mood07, R.raw.mood08, R.raw.mood09,
			R.raw.mood10, R.raw.mood11, R.raw.mood12, R.raw.mood13,
			R.raw.mood14, R.raw.mood15, R.raw.mood16, R.raw.mood17,
			R.raw.mood18, R.raw.mood19, R.drawable.emoji_delete_button,
			R.raw.mood20, R.raw.mood21, R.raw.mood22, R.raw.mood23,
			R.raw.mood24, R.raw.mood25, R.raw.mood26, R.raw.mood27,
			R.raw.mood28, R.raw.mood29, R.raw.mood30, R.raw.mood31,
			R.raw.mood32, R.raw.mood33, R.raw.mood34, R.raw.mood35,
			R.raw.mood36, R.raw.mood37, R.raw.mood38, R.raw.mood39,
			R.drawable.emoji_delete_button, R.raw.mood40, R.raw.mood41,
			R.raw.mood42, R.raw.mood43, R.raw.mood44, R.raw.mood45,
			R.raw.mood46, R.raw.mood47, R.raw.mood48, R.raw.mood49,
			R.raw.mood50, R.raw.mood51, R.raw.mood52, R.raw.mood53,
			R.raw.mood54, R.raw.mood55, R.raw.mood56, R.raw.mood57,
			R.raw.mood58, R.raw.mood59, R.drawable.emoji_delete_button,
			R.raw.mood60, R.raw.mood61, R.raw.mood62, R.raw.mood63,
			R.raw.mood64, R.raw.mood65, R.raw.mood66, R.raw.mood67,
			R.raw.mood68, R.raw.mood69, R.raw.mood70, R.raw.mood71,
			R.raw.mood72, R.raw.mood73, R.raw.mood74, R.raw.mood75,
			R.raw.mood76, R.raw.mood77, R.raw.mood78, R.raw.mood79,
			R.drawable.emoji_delete_button, R.raw.mood80, R.raw.mood81,
			R.raw.mood82, R.raw.mood83, R.raw.mood84, R.raw.mood85,
			R.raw.mood86, R.raw.mood87, R.raw.mood88, R.raw.mood89,
			R.raw.mood90, R.raw.mood91, R.raw.mood92, R.raw.mood93,
			R.drawable.emoji_delete_button };

	/**
	 * 删除emoji标签
	 * @param sendEdit
	 * @param emoji_name
	 */
	public static void deleteEmoji(EditText sendEdit, String emoji_name) {

		if (sendEdit != null) {
			int start = sendEdit.getSelectionStart();
			String content = sendEdit.getText().toString();
			if (TextUtils.isEmpty(content) || start == 0) {
				return;
			}
			String startContent = content.substring(0, start);
			String endContent = content.substring(start, content.length());
			String lastContent = content.substring(start - 1, start);
			int last = startContent.lastIndexOf("[" + emoji_name);
			int lastChar = startContent.substring(0, startContent.length() - 1)
					.lastIndexOf("] ");

			if ("]".equals(lastContent) && last > lastChar) {
				if (last != -1) {
					sendEdit.setText(startContent.substring(0, last)
							+ endContent);
					CharSequence info = sendEdit.getText();
					if (info instanceof Spannable) {
						Spannable spanText = (Spannable) info;
						Selection.setSelection(spanText, last);
					}
					return;
				}
			}
			sendEdit.setText(startContent.substring(0, start - 1) + endContent);
			CharSequence info = sendEdit.getText();
			if (info instanceof Spannable) {
				Spannable spanText = (Spannable) info;
				Selection.setSelection(spanText, start - 1);
			}

		}

	}
}
